home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / NetBignum.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  4.1 KB  |  142 lines

  1. package symantec.itools.db.net;
  2.  
  3. import java.io.DataOutputStream;
  4. import java.io.IOException;
  5. import symjava.lang.Bignum;
  6. import symjava.sql.SQLException;
  7.  
  8. class NetBignum extends NumberField {
  9.    Bignum _bigVal;
  10.  
  11.    int getType() {
  12.       return 83;
  13.    }
  14.  
  15.    void readData(ServerObject data) throws SQLException, IOException, ErrorException {
  16.       String s = ((NetString)data).getString();
  17.       this._bigVal = new Bignum(s);
  18.    }
  19.  
  20.    void writeData(DataOutputStream os) throws IOException {
  21.       try {
  22.          NetString s = new NetString(this.getString());
  23.          s.write(os);
  24.       } catch (SQLException x) {
  25.          throw new IOException(((Throwable)x).getMessage());
  26.       }
  27.    }
  28.  
  29.    public String getString() throws SQLException {
  30.       return ((Field)this).isNull() ? null : this._bigVal.toString();
  31.    }
  32.  
  33.    public boolean getBoolean() throws SQLException {
  34.       if (((Field)this).isNull()) {
  35.          return false;
  36.       } else {
  37.          int i = this._bigVal.intValue();
  38.          return i != 0;
  39.       }
  40.    }
  41.  
  42.    public byte getByte() throws SQLException {
  43.       if (((Field)this).isNull()) {
  44.          return 0;
  45.       } else {
  46.          int i = this._bigVal.intValue();
  47.          return (byte)i;
  48.       }
  49.    }
  50.  
  51.    public short getShort() throws SQLException {
  52.       if (((Field)this).isNull()) {
  53.          return 0;
  54.       } else {
  55.          int i = this._bigVal.intValue();
  56.          return (short)i;
  57.       }
  58.    }
  59.  
  60.    public int getInt() throws SQLException {
  61.       return ((Field)this).isNull() ? 0 : this._bigVal.intValue();
  62.    }
  63.  
  64.    public long getLong() throws SQLException {
  65.       return ((Field)this).isNull() ? 0L : this._bigVal.longValue();
  66.    }
  67.  
  68.    public float getFloat() throws SQLException {
  69.       return ((Field)this).isNull() ? 0.0F : this._bigVal.floatValue();
  70.    }
  71.  
  72.    public double getDouble() throws SQLException {
  73.       return ((Field)this).isNull() ? (double)0.0F : this._bigVal.doubleValue();
  74.    }
  75.  
  76.    public Bignum getBignum(int scale) throws SQLException {
  77.       return ((Field)this).isNull() ? null : new Bignum(this._bigVal, scale);
  78.    }
  79.  
  80.    public void setBoolean(boolean x) throws SQLException {
  81.       if (x) {
  82.          this._bigVal = new Bignum(1);
  83.       } else {
  84.          this._bigVal = new Bignum(0);
  85.       }
  86.  
  87.       super._null = false;
  88.    }
  89.  
  90.    public void setByte(byte x) throws SQLException {
  91.       this._bigVal = new Bignum(x);
  92.       super._null = false;
  93.    }
  94.  
  95.    public void setShort(short x) throws SQLException {
  96.       this._bigVal = new Bignum(x);
  97.       super._null = false;
  98.    }
  99.  
  100.    public void setInt(int x) throws SQLException {
  101.       this._bigVal = new Bignum(x);
  102.       super._null = false;
  103.    }
  104.  
  105.    public void setLong(long x) throws SQLException {
  106.       this._bigVal = new Bignum(x);
  107.       super._null = false;
  108.    }
  109.  
  110.    public void setFloat(float x) throws SQLException {
  111.       this._bigVal = new Bignum((double)x, 15);
  112.       super._null = false;
  113.    }
  114.  
  115.    public void setDouble(double x) throws SQLException {
  116.       this._bigVal = new Bignum(x, 15);
  117.       super._null = false;
  118.    }
  119.  
  120.    public void setBignum(Bignum x) throws SQLException {
  121.       this._bigVal = x;
  122.       super._null = false;
  123.    }
  124.  
  125.    public void setString(String x) throws SQLException {
  126.       this._bigVal = new Bignum(x);
  127.       super._null = false;
  128.    }
  129.  
  130.    public int getSQLType() {
  131.       return 2;
  132.    }
  133.  
  134.    public Object getObject() throws SQLException {
  135.       return new Bignum(this._bigVal);
  136.    }
  137.  
  138.    public void setObject(Object obj) throws SQLException {
  139.       this.setBignum((Bignum)obj);
  140.    }
  141. }
  142.